package com.mcxx.modules.miniSalvation.fundpay.service.read;

import com.mcxx.common.exception.BizException;
import com.mcxx.modules.base.service.read.AreaReadService;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.miniSalvation.fundpay.dao.read.CustomFundPayMemberReadDao;
import com.mcxx.modules.miniSalvation.fundpay.dto.CustomFundPayDTO;
import com.mcxx.modules.miniSalvation.fundpay.dto.CustomFundPayMemberDTO;
import com.mcxx.modules.miniSalvation.fundpay.entity.CustomFundPayMemberEntity;
import com.mcxx.modules.miniSalvation.fundpay.param.CustomFundPayMemberParam;
import com.mcxx.modules.miniSalvation.fundpay.param.FundPayParam;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("customFundPayMemberReadService")
@TaTransactional(readOnly = true)
public class CustomFundPayMemberReadService extends BaseService {
    @Autowired
    private CustomFundPayMemberReadDao customFundPayMemberReadDao;
    @Autowired
    private AreaReadService areaReadService;




    public List<CustomFundPayMemberEntity> getCustomMemberListByMemberId(CustomFundPayDTO customFundPayDTO, List<String> memberIdList, UserAccountVo userAccountVo){


        CustomFundPayMemberParam customFundPayMemberParam = new CustomFundPayMemberParam();

        customFundPayMemberParam.setAreaCode(CommonUtil.invalidArgs(customFundPayMemberParam.getAreaCode()) ? customFundPayDTO.getAreaCode() : customFundPayMemberParam.getAreaCode());
        QueryParamUtil.setBaseParamValue(customFundPayMemberParam, userAccountVo);
        customFundPayMemberParam.setBusinessType(customFundPayDTO.getBusinessType());


        return customFundPayMemberReadDao.getCustomMemberListByMemberId(customFundPayMemberParam, memberIdList);
    }



    public List<CustomFundPayMemberEntity> getCustomMemberListByIdcard(CustomFundPayDTO customFundPayDTO, List<String> idcardList, UserAccountVo userAccountVo){


        CustomFundPayMemberParam customFundPayMemberParam = new CustomFundPayMemberParam();

        customFundPayMemberParam.setAreaCode(CommonUtil.invalidArgs(customFundPayMemberParam.getAreaCode()) ? customFundPayDTO.getAreaCode() : customFundPayMemberParam.getAreaCode());
        QueryParamUtil.setBaseParamValue(customFundPayMemberParam, userAccountVo);

       // customFundPayMemberParam.setPayDate(customFundPayDTO.getPayDate());

       // customFundPayMemberParam.setStandType(packageStandType(customFundPayDTO.getBusinessCode()));

        //customFundPayMemberParam.setType(customFundPayDTO.getType());


        return customFundPayMemberReadDao.getCustomMemberListByIdcard(customFundPayMemberParam, idcardList);
    }


    private String packageStandType(String customFundPayBusinessCode){
        if(Constant.CustomFundPayStand.CITY_DIBAO.equals(customFundPayBusinessCode)){

            return Constant.BusinessStandType.CITY_DIBAO;
        }else if(Constant.CustomFundPayStand.COUNTY_DIBAO.equals(customFundPayBusinessCode)){

            return Constant.BusinessStandType.COUNTY_DIBAO;
        }else if(Constant.CustomFundPayStand.CITY_TEKUN.equals(customFundPayBusinessCode)){

            return Constant.BusinessStandType.CITY_TEKUN;
        }else if(Constant.CustomFundPayStand.COUNTY_TEKUN.equals(customFundPayBusinessCode)){

            return Constant.BusinessStandType.COUNTY_TEKUN;
        }
        throw new BizException("-1", "业务类型错误");
    }



    public Page getMemberByCustomFundPayId(CustomFundPayMemberParam param, PageParam pageParam, UserAccountVo userAccountVo){

        QueryParamUtil.setBaseParamValue(param, userAccountVo);


        customFundPayMemberReadDao.beginPager(pageParam);
        List<CustomFundPayMemberDTO> list = customFundPayMemberReadDao.getMemberByCustomFundPayId(param);


        return customFundPayMemberReadDao.endPager(list);
    }



    public Page getMemberByCustomFundPayIds(CustomFundPayMemberParam param, PageParam pageParam){
        if(CommonUtil.invalidArgs(param.getAreaCode()) == false){
            param.setAreaCode(QueryParamUtil.subAreaCode(param.getAreaCode()));
        }
        customFundPayMemberReadDao.beginPager(pageParam);
        List<CustomFundPayMemberDTO> list = customFundPayMemberReadDao.getMemberByCustomFundPayIds(param);



//            TaAreaPo taAreaPo5 = areaReadService.getAreaByCode(customFundPayMember.getAreaCode());




//            customFundPayMember.setAreaCode(taAreaPo5.getAreaName());

//            String[] areaPath = taAreaPo5.getNamePath().split("/");

//            customFundPayMember.setAreaCodeUsb(areaPath[areaPath.length - 2]);


        return customFundPayMemberReadDao.endPager(list);
    }




    public CustomFundPayMemberDTO getCountFundPay(CustomFundPayMemberParam customFundPayMemberParam){
        return customFundPayMemberReadDao.getCountFundPay(customFundPayMemberParam);
    }


    public CustomFundPayMemberDTO getCountFundPayMemberCount(CustomFundPayMemberParam customFundPayMemberParam){
        return customFundPayMemberReadDao.getCountFundPayMemberCount(customFundPayMemberParam);
    }


    public List<CustomFundPayMemberDTO> exportCustFundPayMemberList(FundPayParam param){ return customFundPayMemberReadDao.exportCustFundPayMemberList(param); }

}
